package com.aistar.service.user.impl;

import com.aistar.mapper.*;
import com.aistar.model.dto.user.RecruitmentAndCompanyDTO;
import com.aistar.model.dto.user.ResumeViewAndCompanyDTO;
import com.aistar.model.entity.Company;
import com.aistar.model.entity.Delivery;
import com.aistar.model.entity.Resume;
import com.aistar.service.user.IMydeliveryService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class MydeliveryServiceImpl implements IMydeliveryService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private ResumeMapper resumeMapper;
    @Autowired
    private DeliveryMapper deliveryMapper;
    @Autowired
    private RecruitmentMapper recruitmentMapper;
    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public List<RecruitmentAndCompanyDTO> delivery(Integer employeeId) {
        List<RecruitmentAndCompanyDTO> lists = new ArrayList<>();
        for (Resume resume:resumeMapper.findByEmployeeId(employeeId)){
            for (Delivery delivery:deliveryMapper.findByResumeId(resume.getId())){
                RecruitmentAndCompanyDTO recruitmentAndCompanyDTO = new RecruitmentAndCompanyDTO();
                recruitmentAndCompanyDTO.setRecruitment(recruitmentMapper.findById(delivery.getRecruitmentId()));
                recruitmentAndCompanyDTO.setCompany(companyMapper.findById(recruitmentMapper.findById(delivery.getRecruitmentId()).getId()));
                recruitmentAndCompanyDTO.setDelivery(delivery);
                lists.add(recruitmentAndCompanyDTO);
            }
        }
        return lists;
    }

    @Override
    public List<RecruitmentAndCompanyDTO> deliveryInterested(Integer employeeId) {
        List<RecruitmentAndCompanyDTO> lists = new ArrayList<>();
        for (Resume resume:resumeMapper.findByEmployeeId(employeeId)){
            for (Delivery delivery:deliveryMapper.findByResumeId(resume.getId())){
                if (delivery.getStatus().equals("有意向")){
                    RecruitmentAndCompanyDTO recruitmentAndCompanyDTO = new RecruitmentAndCompanyDTO();
                    recruitmentAndCompanyDTO.setRecruitment(recruitmentMapper.findById(delivery.getRecruitmentId()));
                    recruitmentAndCompanyDTO.setCompany(companyMapper.findById(recruitmentMapper.findById(delivery.getRecruitmentId()).getId()));
                    recruitmentAndCompanyDTO.setDelivery(delivery);
                    lists.add(recruitmentAndCompanyDTO);
                }
            }
        }
        return lists;
    }

    @Override
    public List<RecruitmentAndCompanyDTO> deliveryNo(Integer employeeId) {
        List<RecruitmentAndCompanyDTO> lists = new ArrayList<>();
        for (Resume resume:resumeMapper.findByEmployeeId(employeeId)){
            for (Delivery delivery:deliveryMapper.findByResumeId(resume.getId())){
                if (delivery.getStatus().equals("无意向")){
                    RecruitmentAndCompanyDTO recruitmentAndCompanyDTO = new RecruitmentAndCompanyDTO();
                    recruitmentAndCompanyDTO.setRecruitment(recruitmentMapper.findById(delivery.getRecruitmentId()));
                    recruitmentAndCompanyDTO.setCompany(companyMapper.findById(recruitmentMapper.findById(delivery.getRecruitmentId()).getId()));
                    recruitmentAndCompanyDTO.setDelivery(delivery);
                    lists.add(recruitmentAndCompanyDTO);
                }
            }
        }
        return lists;
    }

    @Override
    public List<RecruitmentAndCompanyDTO> deliveryYes(Integer employeeId) {
        List<RecruitmentAndCompanyDTO> lists = new ArrayList<>();
        for (Resume resume:resumeMapper.findByEmployeeId(employeeId)){
            for (Delivery delivery:deliveryMapper.findByResumeId(resume.getId())){
                if (delivery.getStatus().equals("待面试")){
                    RecruitmentAndCompanyDTO recruitmentAndCompanyDTO = new RecruitmentAndCompanyDTO();
                    recruitmentAndCompanyDTO.setRecruitment(recruitmentMapper.findById(delivery.getRecruitmentId()));
                    recruitmentAndCompanyDTO.setCompany(companyMapper.findById(recruitmentMapper.findById(delivery.getRecruitmentId()).getId()));
                    recruitmentAndCompanyDTO.setDelivery(delivery);
                    lists.add(recruitmentAndCompanyDTO);
                }
            }
        }
        return lists;
    }

}